<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>学校固定资产管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" href="./css/font.css">
    <link rel="stylesheet" href="./css/xadmin.css">
    <script src="./lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="./js/xadmin.js"></script>
    <!--[if lt IE 9]>
          <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
          <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
        <![endif]-->
</head>

<body>
    <div class="x-nav">
        <span class="layui-breadcrumb">
            <a>首页</a>
            <a>资产变更</a>
            <a>
                <cite>资产变动</cite>
            </a>
        </span>
        <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
            <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
        </a>
    </div>
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body">

                        <div class="layui-card-body">
                            <form class="layui-form">
                                <div class="layui-form-item">
                                    <div class="layui-inline">
                                        <div class="layui-inline layui-show-xs-block">
                                            <input type="text" name="assetsNum" id="assetsNum" placeholder="资产编号" autocomplete="off" class="layui-input">
                                        </div>
                                        <div class="layui-inline layui-show-xs-block">
                                            <input type="text" name="assetsName" id="assetsName" placeholder="资产名称" autocomplete="off" class="layui-input">
                                        </div>
                                        <div class="layui-inline layui-show-xs-block">
                                            <div class="layui-input-inline" style="width: 190px;">
                                                <select id="L_state" name="ModifyState" lay-filter="state">
                                                    <option value="">变更状态</option>
                                                    <option value="0">待确认</option>
                                                    <option value="1">已完成</option>
                                                    <option value="2">已拒绝</option>
                                                </select>
                                            </div>
                                        </div>
                                        <div class="layui-inline layui-show-xs-block">
                                            <button class="layui-btn" id="search" lay-submit="" lay-filter="search">
                                                <i class="layui-icon">&#xe615;查询</i>
                                            </button>
                                        </div>
                                    </div>

                                </div>
                            </form>
                        </div>
                        <div class="layui-card-body layui-form">
                            <table id="modify"></table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
</body>
<script>
    //初始状态
    layui.use('table', function () {
        var table = layui.table;
        var from = layui.from;
        //表格实例化
        table.render({
            elem: '#modify'
            , height: 500
            , headers: { 'token': sessionStorage.getItem("token") }
            , url: sessionStorage.getItem("api") + 'modifylog/list'
            , where: { StatusStr: status }
            , page: true
            , request: {
                pageName: 'PageIndex'
                , limitName: 'PageSize'
            }
            , parseData: function (res) {
                return {
                    "code": res.Data.Code,
                    "msg": res.Data.Msg,
                    "count": res.Data.Count,
                    "data": res.Data.Data
                };
            }
            , cols: [
                [
                    { type: 'numbers', title: '序号', width: 80 }
                    , { field: 'AssetsNum', title: '编号' }
                    , { field: 'AssetsName', title: '资产名称' }
                    , { field: 'OldStatus', title: '原状况' }
                    , { field: 'NewStatus', title: '现状况' }
                    , { field: 'ModifyDescribe', title: '变更描述', width: 150 }
                    , {
                        title: '接收人', width: 150,
                        templet: function (d) {
                            return d.AcceptDepartment + " " + d.AcceptName
                        }
                    }
                    , {
                        title: '申请人', width: 150,
                        templet: function (d) {
                            return d.ModifyDepartment + " " + d.ModifyName
                        }
                    }
                    ,{field:"CreateDateString",title:"变动时间", width: 150 }
                    , {
                        title: '操作',
                        templet: '#button'
                    }


                ]
            ]
        });



    });

</script>
<script type="text/html" id="button">
    {{# if(d.ModifyState=="0"){     }}
    {{# if(d.IsForMe){     }}
        <input type="button" class="layui-btn layui-btn-radius layui-btn-normal" lay-submit lay-filter = "agree" id="{{d.Id}}"  value="接受">
        <input type="button" class="layui-btn layui-btn-radius layui-btn-danger" lay-submit lay-filter = "refuse" id="{{d.Id}}"  value="拒绝">
    {{# }else{     }}
    <span class="layui-badge layui-bg-blue">待同意</span>
    {{#  }    }}
    {{#  }else if(d.ModifyState=="1"){    }}
    <span class="layui-badge layui-bg-green">已完成</span>
    {{# }else{     }}
        <span class="layui-badge layui-bg-gray">已拒绝</span>
    {{# }     }}
    
</script>
<script>
    layui.use(['form', 'layer', 'jquery'],
        function () {
            $ = layui.jquery;
            var form = layui.form,
                layer = layui.layer;
            layui.use('table', function () {
                var table = layui.table;
                //监听提交
                form.on('submit(search)',
                    function (data) {
                        table.reload('modify', {
                            where: data.field
                            , page: {
                                curr: 1 //重新从第 1 页开始
                            }
                        });
                        return false;
                    });
            })

            //接受
            form.on('submit(agree)',
                function (data) {
                    modify(data, 1);
                    return false;
                });
            //拒绝
            form.on('submit(refuse)',
                function (data) {
                    modify(data, 2);
                    return false;
                });

            function modify(data, modifyState) {
                $.ajax({
                    type: "PUT",
                    headers: { "token": sessionStorage.getItem("token") },
                    url: sessionStorage.getItem("api") + "modifylog/" + data.elem.id + "/infos/"+modifyState,
                    contentType: "application/x-www-form-urlencoded",
                    dataType: "Json",
                    success: function (res) {
                        if (res.Code == 200) {
                            layer.closeAll('loading');
                            layer.msg(res.Data, {
                                time: 1500
                            }, function () {
                                window.location.reload();
                            })
                        } else {
                            layer.msg(res.ErrorMessage);
                        }
                    }
                });
            }
        });
</script>

</html>